#ifndef LOG_H
#define LOG_H

#include <cstdio>
#include <cstdarg>

enum LogLevel {
    kTrace = 0,
    kDebug = 1,
    kInfo = 2,
    kWarn = 3,
    kError = 4,
};

void write_log(LogLevel level, int print_stacktrace, const char *func_name, int line, const char *fmt, ...)
{
    if (level < kInfo) {
        return;
    }
    
    char buf[1024] = {0};
    printf("[%s][%s][%d] ", __FILE__, func_name, line);
    va_list args;
    va_start(args, fmt);
    vsnprintf(buf, sizeof(buf), fmt, args);
    va_end(args);
    printf("%s\n", buf);
}

#define LogError(fmt, ...) write_log(kError, 0, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define LogWarn(fmt, ...) write_log(kWarn, 0, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define LogInfo(fmt, ...) write_log(kInfo, 0, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define LogDebug(fmt, ...) write_log(kDebug, 0, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define LogTrace(fmt, ...) write_log(kTrace, 0, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)

#endif // LOG_H